home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12148 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Arrays of strings (linking)
  5. Date: Fri, 29 Mar 96 13:11:59 GMT
  6. Organization: none
  7. Message-ID: <828105119snz@genesis.demon.co.uk>
  8. References: <4jbkpg$5m7@news.ariadne-t.gr> <3159F9EC.1835@willows.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <3159F9EC.1835@willows.com>
  15.            tarang@willows.com "Tarang Deshpande" writes:
  16.  
  17. >char* strjoin ( char *str1, char* str2 )
  18.  
  19. strjoin is a reserved identifier - you should call the function something
  20. else (i.e. something that doesn't start with str followed by a lowercase
  21. letter) e.g. str_join or Strjoin or strJoin are all OK.
  22.  
  23. >{
  24. >
  25. >        char *str = malloc ( strlen ( str1 ) + strlen ( str2 ) + 1 );
  26. >
  27. >        if ( str )
  28. >        {
  29. >                *str = '\0';
  30. >                strcat ( str, str1 );
  31.  
  32. Or just use strcpy().
  33.  
  34. >                strcat ( str, str2 );
  35.  
  36. Or replace all 3 lines with:
  37.  
  38.                  sprintf(str, "%s%s", str1, str2);
  39. >        }
  40. >
  41. >        return ( str );
  42. >
  43. >}
  44.  
  45. -- 
  46. -----------------------------------------
  47. Lawrence Kirby | fred@genesis.demon.co.uk
  48. Wilts, England | 70734.126@compuserve.com
  49. -----------------------------------------
  50.